var data1 = [{'id':'1','customertype':'text1','customersource':'text2','nomailreceived':'text3','nomailsent':'text4','customercontactdays':'text5','advancewarning':'text6','cdate':'text7','note':'text8'},
    {'id':'2','customertype':'text1','customersource':'text2','nomailreceived':'text3','nomailsent':'text4','customercontactdays':'text5','advancewarning':'text6','cdate':'text7','note':'text8'},
    {'id':'3','customertype':'text1','customersource':'text2','nomailreceived':'text3','nomailsent':'text4','customercontactdays':'text5','advancewarning':'text6','cdate':'text7','note':'text8'},
    {'id':'4','customertype':'text1','customersource':'text2','nomailreceived':'text3','nomailsent':'text4','customercontactdays':'text5','advancewarning':'text6','cdate':'text7','note':'text8'}];

var $=layui.jquery,delusergroupul,table=layui.table;
table.render({
    elem: '#publicpoolid'
    ,data:data1
    ,toolbar: '#toolbarDemo'
    ,cols: [[
        {checkbox: true, fixed: true}
        ,{field:'customertype', title:'客户类型', fixed: true, sort: true}
        ,{field:'customersource', title:'客户来源', fixed: true}
        ,{field:'nomailreceived', title:'未收到邮件', fixed: true}
        ,{field:'nomailsent', title:'未发出邮件', fixed: true}
        ,{field:'customercontactdays', title:'客户联系天数', fixed: true}
        ,{field:'advancewarning', title:'提前提醒天数', fixed: true}
        ,{field:'cdate', title:'启用日期', fixed: true}
        ,{field:'note', title:'备注', fixed: true}
        ,{fixed: 'right', width:63, align:'center', toolbar: '#editor', title:'操作'}
    ]]
    ,id: 'publicpooltableid'
    ,height: $(document).height() - $('#publicpoolid').offset().top - 50
    ,page: true
});
table.on('toolbar(publicpooltable)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
        case 'new':
            parent.intab("views/jsp/BasicData/tpl/newuppubicpool.jsp","新增公共池");
            break;
        case 'delete':
            var data = checkStatus.data;
            var delid = [];
            for (var i = 0;i<data.length;i++){
                delid.push(data[i].id)
            }
            layer.msg('需要删除的数据ID为：'+ JSON.stringify(delid) + ',执行删除');
            table.reload('publicpooltableid',{}); //ajax删除成功之后刷新表格
            break;
    };
});
//监听工具条
table.on('tool(publicpooltable)', function(obj){
    if(obj.event === 'edit'){
        parent.intab("views/jsp/BasicData/tpl/newuppubicpool.jsp?id="+obj.data.id,"修改公共池")
    }
});